package by.airlanterns.dto;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.validator.constraints.NotEmpty;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: Sergey
 * Date: 27.01.13
 * Time: 14:09
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "lantern")
public class Lantern {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id_lantern")
    private Integer idLantern;

    @Column(name = "description")
    @NotEmpty
    private String description;

    @Column(name = "img_url")
    @NotEmpty
    private String imgUrl;

    @Column(name = "price")
    @NotNull
    private Integer price;

    @ManyToOne
    @JoinColumn(name = "fk_id_category", nullable = false)
    @Fetch(value = FetchMode.SELECT)
    private Category category = new Category();

    @OneToMany(mappedBy = "lantern", fetch = FetchType.EAGER)
    @Fetch(value = FetchMode.SELECT)
    @Cascade(value = org.hibernate.annotations.CascadeType.ALL)
    @JsonIgnore
    private Set<UserOrder> userOrders;

    public Integer getIdLantern() {
        return idLantern;
    }

    public void setIdLantern(Integer idLantern) {
        this.idLantern = idLantern;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public Set<UserOrder> getUserOrders() {
        return userOrders;
    }

    public void setUserOrders(Set<UserOrder> userOrders) {
        this.userOrders = userOrders;
    }
}
